<template>
  <div>
    <MySearch :city="city"/>
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="item in swiperList" :key="item.id">
        <img :src="imgSrc + item.imgSrc" alt="" />
      </van-swipe-item>
    </van-swipe>
    <van-grid :column-num="4" :border="false">
      <van-grid-item icon="wap-home-o" text="整租" />
      <van-grid-item icon="friends-o" text="合租" />
      <van-grid-item icon="location-o" text="地图找房" />
      <van-grid-item to="/gozuhome" icon="home-o" text="去出租" />
    </van-grid>
    <div class="home_info">
      <div class="herder_txt">
        <h4>租房小组</h4>
        <p>更多</p>
      </div>
      <div class="bottom_info">
        <div class="bottom_info_list" v-for="item in groupslist" :key="item.id">
          <img
            src="@/assets/logo.png"
          />
          <div class="txt">
            <p>{{item.title}}</p>
            <p>{{item.desc}}</p>
          </div>
        </div>
        </div>
      </div>
    </div>

</template>

<script>
import MySearch from '@/components/MySearch.vue'
import { getMyCity } from '@/utils/city'
import { getSwiper, getGroups } from '@/api/home'
export default {
  name: 'HomePage',
  components: { MySearch },
  data () {
    return {
      value: '',
      swiperList: [],
      imgSrc: 'http://liufusong.top:8080',
      groupslist: [],
      city: ''
    }
  },
  async created () {
    // 获取首页定位城市
    const data = await getMyCity()
    this.city = data.label
    // 轮播图接口
    const { body } = await getSwiper()
    // 租房小组
    const res = await getGroups(this.$store.state.home.cityId)
    this.groupslist.push(...res.body)
    // 防止页面结构没有渲染出来
    this.$nextTick(() => {
      this.swiperList.push(...body)
    })
  },
  methods: {
    onSearch () {}
  }
}
</script>

<style lang="less" scoped>
  .my-swipe {
    height: 212px;
    .van-swipe-item {
      color: #fff;
      font-size: 20px;
      text-align: center;
      img {
        width: 100%;
      }
    }
  }
  ::v-deep .van-grid-item__icon {
    padding: 14px;
    font-size: 34px;
    color: rgb(33, 185, 122);
    background-color: #f2fbf7;
    border-radius: 50%;
  }
  .home_info {
    height: 187px;
    padding: 0 10px;
    background-color: #f6f5f6;
    .herder_txt {
      display: flex;
      justify-content: space-between;
      padding: 15px 0 0 6px;
      p {
        font-size: 14px;
        color: #787d82;
      }
    }
    .bottom_info {
      width: 100%;
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      .bottom_info_list {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-radius: 4px;
        margin: 10px 10px 2px 0;
        background-color: #fff;
        height: 60px;
        width: 46%;
        img {
          width: 50px;
          height: 50px;
          margin-left: 10px;
        }
        .txt {
          font-size: 14px;
          margin-right: 16px;
        }
      }
    }
  }
</style>
